#!/usr/bin/python3

import threading
import time
from NOVEL.BQK.BQKWebsite import *
from REQUEST.RequestUtil import *
class NovelThread (threading.Thread):

    def __init__(self, threadID, categoryUrl, categoryName, indexUrl):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.indexUrl = indexUrl
        self.categoryUrl = categoryUrl
        self.categoryName = categoryName
        self.request = RequestUtil()

    '''
       解析目录(由线程执行 )
       '''
    def analysisCatalog(self, refUrl):
        html = self.request.getHtml(refUrl).text
        novels = BeautifulSoup(html, 'html5lib').find_all('div', class_='l bd')[0].find_all('span', class_='s2')
        for novelInfo in novels:
            novelTitle = novelInfo.text
            novelRef = self.indexUrl + novelInfo.a.get('href')
            print(novelTitle, novelRef)
            novel = Novel(indexUrl=self.indexUrl, catalogUrl=novelRef)
            novel.copyNovel()

    def run(self):
        print("开始线程：" + self.categoryName)
        self.analysisCatalog(refUrl = self.categoryUrl)
        print("退出线程：" + self.categoryName)